package edu.cicese.alz;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 31/05/12
 * Time: 05:03 PM
 */
public class Subject implements Comparable<Subject> {
	private int userID;
	private String name;
	private String age;

	private String lat;
	private String lon;

	private boolean selected = false;

	private boolean[] DSVs;
	private boolean hasAccelerometerDsv, hasGPSDsv, hasNFCDsv, hasWIFIDsv;

	public Subject() {}

	public Subject(int userID) {
		this.userID = userID;
	}

	public Subject(int userID, String name) {
		this.userID = userID;
		this.name = name;
	}

	public Subject(int userID, String name, boolean selected) {
		this.userID = userID;
		this.name = name;
		this.selected = selected;
	}

	public Subject(int userID, String name, boolean selected, boolean[] DSVs) {
		this.userID = userID;
		this.name = name;
		this.selected = selected;
		this.DSVs = DSVs;
//		this.hasAccelerometerDsv = DSVs[0]; //0:ACC 1:GPS 2:NFC 3:WIFI
//		this.hasGPSDsv = DSVs[1];
//		this.hasNFCDsv = DSVs[2];
//		this.hasWIFIDsv = DSVs[3];
	}

	public Subject(int userID, String name, String age) {
		this.userID = userID;
		this.name = name;
		this.age = age;
	}

	public Subject(int userID, String name, String age, String lat, String lon) {
		this.userID = userID;
		this.name = name;
		this.age = age;
		this.lat = lat;
		this.lon = lon;
	}

	public int getUserID() {
		return userID;
	}

	public void setUserID(int userID) {
		this.userID = userID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getLat() {
		return lat;
	}

	public void setLat(String lat) {
		this.lat = lat;
	}

	public String getLon() {
		return lon;
	}

	public void setLon(String lon) {
		this.lon = lon;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	public int compareTo(Subject s) {
		System.out.println("Comparing");
		return s.userID - this.userID;
	}

	public boolean equals(Subject s) {
		return name.equals(s.getName()) && age.equals(getAge()) && lat.equals(s.getLat()) && lon.equals(s.getLon());
	}

	public boolean equals(String name, String age, String lat, String lon) {
		return this.name.equals(name) && this.age.equals(age) && this.lat.equals(lat) && this.lon.equals(lon);
	}

	//	private boolean newSubject;

	// Database
//	private static Connection connection;
//	private static Statement statement;
//	private static ResultSet resultSet;
//
//	public static ResultSet getSubjects() {
//		if (openConnection()) {
//			try {
//				return statement.executeQuery(Query.querySubject());
//			} catch (SQLException e) {
//				e.printStackTrace();
//				Query.close(connection, statement, resultSet);
//				return null;
//			}
//		} else {
//			System.out.println("Couldn't connect to database.");
//			return null;
//		}
//	}
//
//	public static ResultSet getSubjects(String name) {
//		if (openConnection()) {
//			try {
//				return statement.executeQuery(Query.querySubject(name));
//			} catch (SQLException e) {
//				e.printStackTrace();
//				Query.close(connection, statement, resultSet);
//				return null;
//			}
//		} else {
//			System.out.println("Couldn't connect to database.");
//			return null;
//		}
//	}
//
//	public static ResultSet getSubjects(int userID) {
//		if (openConnection()) {
//			try {
//				return statement.executeQuery(Query.querySubject(userID));
//			} catch (SQLException e) {
//				e.printStackTrace();
//				Query.close(connection, statement, resultSet);
//				return null;
//			}
//		} else {
//			System.out.println("Couldn't connect to database.");
//			return null;
//		}
//	}
//
//	public static boolean openConnection() {
//		try {
//			// This will load the MySQL driver, each DB has its own driver
//			Class.forName("com.mysql.jdbc.Driver");
//			// Setup the connection with the DB
//			connection = DriverManager.getConnection("jdbc:mysql://localhost/alzheimerdb", "root", "alz");
//			// Statements allow to issue SQL queries to the database
//			statement = connection.createStatement();
//			return true;
//		} catch (ClassNotFoundException | SQLException e) {
//			e.printStackTrace();
//			return false;
//		}
//	}
//
//	public static void close() {
//		Query.close(connection, statement, resultSet);
//	}



	public boolean hasAccelerometerDsv() {
		return hasAccelerometerDsv;
	}

	public boolean hasGPSDsv() {
		return hasGPSDsv;
	}

	public boolean hasNFCDsv() {
		return hasNFCDsv;
	}

	public boolean hasWIFIDsv() {
		return hasWIFIDsv;
	}

	public void setAccelerometerDsv(boolean hasAccelerometerDsv) {
		this.hasAccelerometerDsv = hasAccelerometerDsv;
	}

	public void setGPSDsv(boolean hasGPSDsv) {
		this.hasGPSDsv = hasGPSDsv;
	}

	public void setNFCDsv(boolean hasNFCDsv) {
		this.hasNFCDsv = hasNFCDsv;
	}

	public void setWIFIDsv(boolean hasWIFIDsv) {
		this.hasWIFIDsv = hasWIFIDsv;
	}

	public boolean hasDSVFile(int type) {
		return DSVs[type];
	}
}
